import Vue from 'vue'
import Router from 'vue-router'
// import Login from '../components/Login'
// import Home from '../components/Home'
// import user from '../views/user'
// import rights from '../views/power/rights'
// import roles from '../views/power/roles'
// import goods from '../views/goods'
// import cate from '../views/goods/params'
// import goodsList from '../views/goods/goodsList'
// import addGoods from '../views/goods/addGoods'
// import order from '../views/order/order'
// import report from '../views/report/report'
// 第一组
const Login = () => import(/* webpackChunkName: "login-home" */ '../components/Login')
const Home = () => import(/* webpackChunkName: "login-home" */ '../components/Home')
// 第二组
const user = () => import(/* webpackChunkName: "user-rights-roles" */ '../views/user')
const rights = () => import(/* webpackChunkName: "user-rights-roles" */ '../views/user')
const roles = () => import(/* webpackChunkName: "user-rights-roles" */ '../views/user')
// 第三组
const goods = () => import(/* webpackChunkName: "godds-cate" */ '../views/goods')
const cate = () => import(/* webpackChunkName: "godds-cate" */ '../views/goods/params')

const goodsList = () => import(/* webpackChunkName: "goddsList-addGoods" */ '../views/goods/params')
const addGoods = () => import(/* webpackChunkName: "goddsList-addGoods" */ '../views/goods/addGoods')

const order = () => import(/* webpackChunkName: "goddsList-addGoods" */ '../views/order/order')
const report = () => import(/* webpackChunkName: "goddsList-addGoods" */ '../views/report/report')

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/', redirect: '/login'
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/home',
      component: Home,
      redirect: '/user',
      children: [
        { path: '/user', component: user },
        { path: '/rights', component: rights },
        { path: '/roles', component: roles },
        { path: '/goods', component: goods },
        { path: '/cate', component: cate },
        { path: '/goodsList', component: goodsList },
        { path: '/addGoods', component: addGoods },
        { path: '/order', component: order },
        { path: '/report', component: report }
      ]
    },
  ]

})
// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') return next()
//   // 获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) return next('/login')
//   next()
// })
export default router
